#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int c;
	scanf("%d",&c);
	while(c--){
		int N,L,W,H; //consider L >= W >= H
		scanf("%d",&N);
		int tmp_min = 100000000;
		int maxh = 10;
		if(N < 10)maxh = N;
		//enumerate H
		for(int H = 1; H <= maxh; H++){
			if(N%H != 0)continue;
			int remain = N/H;
			//enumuerate W
			for(int W = H; W <= remain; W++){
				if(remain%W != 0)continue;
				L = remain/W;
				int tmp = (L*W + L*H + W*H)*2;
				if(tmp < tmp_min) tmp_min = tmp;
			}
		}
		printf("%d\n",tmp_min);
		
	}
	return 0;
}